package com.guigu.ssm.controller;

import com.guigu.ssm.pojo.Account;
import com.guigu.ssm.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class AccountController {

    @Autowired(required = false)
    AccountService dao;

    @RequestMapping("/login")
    @ResponseBody
    public boolean login(Account aa, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Account login = dao.login(aa);
        if (login==null){
            return false;
        }else {
            req.getSession().setAttribute("card",login.getCardno());
           return true;
        }
    }


    @RequestMapping("/tc")
    public void tc(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("6666");
        req.getSession().removeAttribute("card");
        resp.sendRedirect("login.jsp");
    }
}
